import { find, Node, sp, UITransform, v3 } from "cc";
import { ViewUtil } from "db://oops-framework/core/utils/ViewUtil";
import { SpineFinishedRelease } from "db://oops-framework/libs/animator-effect/2d/SpineFinishedRelease";
import { EffectFinishedRelease } from "db://oops-framework/libs/animator-effect/EffectFinishedRelease";
import { Role } from "../../../../role/Role";

/** 角色自身特效 */
export class RoleEffect {
      /** 死亡小鬼动画 */
      static die(parent: Node){
        var node = ViewUtil.createPrefabNode("game/role/xiaogui");
        node.addComponent(SpineFinishedRelease);
        node.parent = parent;
    }

    static skill(target: Role, anim: any) {
        var effect = ViewUtil.createPrefabNode("game/battle/skill/effect_attacker");
        var efrs = effect.addComponent(EffectFinishedRelease);
        this.setPos(target, effect, anim);
    }
    private static setPos(target: Role, effect: Node, anim: any) {
        // 层级
        if (anim.animpos == 0) {
            effect.parent = find("content/effect_top", target.RoleView.node);
        }
        else if (anim.animpos == 1) {
            effect.parent = find("content/effect_bottom", target.RoleView.node);
        }

        // 特效位置
        let node = find("content/spine", target.RoleView.node)!;
        let y = 0;
        switch (anim.pos) {
            case 1:
                y = effect.parent!.getComponent(UITransform)!.height;
                break;
            case 2:
                y = effect.parent!.getComponent(UITransform)!.height / 2;
                break;
            case 3:
                y = 0;
                break;
            default:
                break;
        }
        effect.setPosition(node.getPosition().x, y);
        let spine = effect.getComponent(sp.Skeleton)!;

        if (anim.loop == 0)
            spine.setAnimation(0, "animation", false);
        else
            spine.setAnimation(0, "animation", true);
    }
}